home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiniExamples / AppKit / PaginationLab / MyPageLayout.m < prev    next >
Text File  |  1995-06-12  |  4KB  |  114 lines

  1. /* MyPageLayout.m
  2.  * Purpose: A subclass of the PageLayout panel that displays more of the
  3.  * information from NXApp's PrintInfo object.  If you add an accessory
  4.  * View to the PageLayout panel, you commonly need to subclass it to
  5.  * keep your fields in sync with the user's chosen units.
  6.  *
  7.  * You may freely copy, distribute, and reuse the code in this example.
  8.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  9.  * fitness for any particular use.
  10.  *
  11.  * Written by: Samuel Streeper
  12.  * Created: (04/April/91)
  13.  */
  14.  
  15. #import "MyPageLayout.h"
  16. #import "MyPrintInfo.h"
  17. #import "BigView.h"
  18.  
  19. @implementation MyPageLayout
  20.  
  21. - (int) runModal
  22. {
  23.     if (!p1AccessoryView)
  24.     {
  25.         //  Initialization probably belongs in new, but [PageLayout new]
  26.         //    does really funky stuff that breaks this...
  27.         //    here we load the nib file that contains our accessory view.
  28.         //  This code only gets executed once, because the nib initializes
  29.         //  the p1AccessoryView outlet to a meaningful value.
  30.         
  31.         [NXApp loadNibSection:"MyPageLayout.nib" owner:self withNames:NO];
  32.         [self setAccessoryView:p1AccessoryView];
  33.     }
  34.  
  35.     return [super runModal];
  36. }
  37.  
  38. - pickedUnits:sender
  39. /*
  40.  * Called when the user selects different units (e.g. cm or inches).
  41.  * Must update the margin fields.
  42.  */
  43. {
  44.     float old, new;
  45.  
  46.     [self convertOldFactor:&old newFactor:&new];
  47.     [[margins cellAt:0:0] setFloatValue:new * [[margins cellAt:0:0] floatValue] / old];
  48.     [[margins cellAt:1:0] setFloatValue:new * [[margins cellAt:1:0] floatValue] / old];
  49.     [[margins cellAt:2:0] setFloatValue:new * [[margins cellAt:2:0] floatValue] / old];
  50.     [[margins cellAt:3:0] setFloatValue:new * [[margins cellAt:3:0] floatValue] / old];
  51.  
  52.     return [super pickedUnits:sender];
  53. }
  54.  
  55. // When the panel comes up, read the global printInfo object and set the
  56. // panels fields appropriately.
  57. - readPrintInfo
  58. {
  59.     float conversion, dummy;
  60.     NXCoord left, right, top, bottom;
  61.     id pi;
  62.     
  63.     [super readPrintInfo];
  64.  
  65.     pi = [NXApp printInfo];
  66.     [[centerButtons cellAt:0:0] setState:[pi isHorizCentered]];
  67.     [[centerButtons cellAt:1:0] setState:[pi isVertCentered]];
  68.  
  69.     [vertButtons selectCellAt:[pi vertPagination]:0];
  70.     [horButtons selectCellAt:[pi horizPagination]:0];
  71.  
  72.     [paginationButtons selectCellAt:([[NXApp printInfo] paginationMode]):0];
  73.     
  74.     [[MyPageLayout new] convertOldFactor:&conversion newFactor:&dummy];
  75.     [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
  76.     [[margins cellAt:0:0] setFloatValue:left * conversion];
  77.     [[margins cellAt:1:0] setFloatValue:right * conversion];
  78.     [[margins cellAt:2:0] setFloatValue:top * conversion];
  79.     [[margins cellAt:3:0] setFloatValue:bottom * conversion];
  80.  
  81.     return self;
  82. }
  83.  
  84. // If the user hits OK, this method saves the panels settings to the
  85. // global printInfo object.
  86. - writePrintInfo
  87. {
  88.     id pi;
  89.     float conversion, dummy;
  90.  
  91.     [super writePrintInfo];
  92.     pi = [NXApp printInfo];
  93.     [self convertOldFactor:&conversion newFactor:&dummy];
  94.     if (conversion) {
  95.         [pi setMarginLeft:[[margins cellAt:0:0] floatValue] / conversion
  96.                 right:    [[margins cellAt:1:0] floatValue] / conversion
  97.                 top:    [[margins cellAt:2:0] floatValue] / conversion
  98.                 bottom:    [[margins cellAt:3:0] floatValue] / conversion];
  99.     }
  100.     
  101.     [pi setHorizCentered: [[centerButtons cellAt:0:0] state]];
  102.     [pi setVertCentered: [[centerButtons cellAt:1:0] state]];
  103.  
  104.     [pi setVertPagination: [vertButtons selectedRow]];
  105.     [pi setHorizPagination: [horButtons selectedRow]];
  106.  
  107.     [[NXApp printInfo] setPaginationMode:([paginationButtons selectedRow])];
  108.     return self;
  109. }
  110.  
  111.  
  112. @end
  113.  
  114.